package lyq.zkhw;

import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Date;

public class TimeServer extends Thread{


        private int port=0;

        public TimeServer(int port) {
            this.port=port;
        }

        @Override
        public void run() {
            //启动serversocket监听一个端⼝

            try {
                ServerSocket serverSocket = new ServerSocket(port);
                System.out.println("监听端口"+port);
                while (true){
                    Socket socket = serverSocket.accept();
                    OutputStream outputStream = socket.getOutputStream();
                    outputStream.write(new Date().toString().getBytes(StandardCharsets.UTF_8));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }


        }
    }